package xuegao.study.mall.admin.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import xuegao.study.mall.common.api.CommonResult;

/**
 * 全局异常处理类,针对不同的异常,使用不同的方式
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    private Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ResponseBody
    @ExceptionHandler(value = FeignInvokeException.class)
    public CommonResult handleFeignException(FeignInvokeException e) {
        log.error("feign invoke error", e);
        String detailMessage = e.getMessage();
        return CommonResult.failed(detailMessage);
    }

    @ResponseBody
    @ExceptionHandler(value = RuntimeException.class)
    public CommonResult handleRuntimeException(RuntimeException e) {
        log.error("method invoke error", e);
        return CommonResult.failed("系统异常,请联系管理员!");
    }
}
